import router from "@/router/index";
import user from "@/views/system/user.vue"
// const modules = import.meta.glob('@/views/*/*.vue')  
export const dynamicRoutes = (menu:[]) => {
    let arr:any = []
    if(!menu || menu.length === 0) {
        // 如果没有菜单列表，直接返回
        return arr;
    }
    menu.forEach((item:any) => {
        if(!item.children || item.children.length === 0) {
            
            // 如果没有子菜单，直接添加路由
            let menuItem = {
                path: "/" + item.Name,
                name: item.Name,
                component: () => import(`@/views/${item.Href}.vue`),
                children:[]
            }
            // 添加路由
            console.log(menuItem)
            arr.push(menuItem)
        }else{
            // let menuItem = []
            item.children.forEach((child:any) => {
              console.log(`@/views/${child.Href}.vue`)
                let childItem = {
                    path: "/" + child.Name,
                    name: child.Name,
                    component: () => import(`@/views/${child.Href}.vue`)
                }
                arr.push(childItem)
            })
        }
    })
    // router.addRoute("ss_system", menuItem)
    for(let i = 0; i < arr.length; i++) {
        router.addRoute("ss_system", arr[i])
    }
}
